﻿from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.out.write("""
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- saved from url=(0014)about:internet -->
<head>
    <title>Silverlight Project Test Page </title>
    <style type="text/css">
        html, body
        {
            height: 100%;
            overflow: auto;
        }
        body
        {
            padding: 0;
            margin: 0;
        }
        #silverlightControlHost
        {
        }
    </style>

    <script type="text/javascript" src="js/Silverlight.js"></script>

    <script type="text/javascript" src="js/json2.js"></script>

    <script type="text/javascript" src="js/SilverLoggerHelper.js"></script>

    <script type="text/javascript">
        function onSilverlightError(sender, args) {

            var appSource = "";
            if (sender != null && sender != 0) {
                appSource = sender.getHost().Source;
            }
            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\\n";

            errMsg += "Code: " + iErrorCode + "    \\n";
            errMsg += "Category: " + errorType + "       \\n";
            errMsg += "Message: " + args.ErrorMessage + "     \\n";

            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \\n";
                errMsg += "Line: " + args.lineNumber + "     \\n";
                errMsg += "Position: " + args.charPosition + "     \\n";
            }
            else if (errorType == "RuntimeError") {
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \\n";
                    errMsg += "Position: " + args.charPosition + "     \\n";
                }
                errMsg += "MethodName: " + args.methodName + "     \\n";
            }

            throw new Error(errMsg);
        }
    </script>

    <script type="text/javascript">
        var Data = {
            elements: [
                {
                    type: "line",
                    legend_name: "Y=sin(x)",
                    fill_color: "dodgerblue",
                    line_stroke_color: "powderblue",
                    values: []
                },
                {
                    type: "line",
                    legend_name: "Y=cos(x)",
                    fill_color: "deeppink",
                    line_stroke_color: "pink",
                    values: []
                }
    	    ],
            title: "Trigonometric Function",
            x_axis: {
                step: 8,
                label_start_from_zero: true
            }
        };

        var d1 = [];
        var d2 = [];
        for (var i = 0; i <= 32; i++) {
            d1.push(Math.round(Math.sin(i * Math.PI / 16) * 1000) / 1000);
            d2.push(Math.round(Math.cos(i * Math.PI / 16) * 1000) / 1000);
        }
        Data.elements[0].values = d1;
        Data.elements[1].values = d2;
        Data.x_axis.labels = ["0", "π/2", "π", "3π/2", "2π"];

        function GetData() {
            return JSON.stringify(Data);
        }
        
    </script>

</head>
<body>
    <h1>SilverChart Sample Site</h1>
    <p>
    SilverChart is a chart package implemented in Silverlight 2. It can be integrate in any Web Based application.
    </p>
    <p>
    Data are fed on JavaScript? or Http invocation. It make SilverChart compatible with all language.
    </p>
    <p>
    You can find project source code at <a href="http://code.google.com/p/silverchart/">SilverChart Project</a>.
    Last binary package version is 0.0.1. Click <a href="http://silverchart.googlecode.com/files/SilverChart_0.0.1.xap">here</a> to download it.
    <a href="http://code.google.com/p/silverchart/downloads/list?q=label:Featured">All binary downloads</a>
    </p>
    <h2>Sample</h2>
    <!-- Runtime errors from Silverlight will be displayed here.
	This will contain debugging information and should be removed or hidden when debugging is completed -->
    <div id='errorLocation' style="font-size: small; color: Gray;">
    </div>
    <div id="silverlightControlHost">
        <object data="data:application/x-silverlight," type="application/x-silverlight-2"
            width="550" height="250">
            <param name="source" value="xap/SilverChart.xap" />
            <param name="onerror" value="onSilverlightError" />
            <param name="background" value="white" />
            <param name="initParams" value="onGetData=GetData" />
            <a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
                <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight"
                    style="border-style: none" />
            </a>
        </object>
        <iframe style='visibility: hidden; height: 0; width: 0; border: 0px'></iframe>
    </div>
    <p>
    Copy the code list below to a HTML file and open the file in your broswer(currently, support IE, Firefox, Chrome, Safari in Windows OS/Mac OS). <a href="more_samples">More Samples</a>
    </p>
    <div style="border:black solid 1px;font-size: small;width:700px">
    <pre>&lt;html&gt;
&lt;head&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;js/json2.js&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
        var Data = {
            elements: [
                {
                    type: &quot;line&quot;,
                    legend_name: &quot;Y=sin(x)&quot;,
                    fill_color: &quot;dodgerblue&quot;,
                    line_stroke_color: &quot;powderblue&quot;,
                    values: []
                },
                {
                    type: &quot;line&quot;,
                    legend_name: &quot;Y=cos(x)&quot;,
                    fill_color: &quot;deeppink&quot;,
                    line_stroke_color: &quot;pink&quot;,
                    values: []
                }
    	    ],
            title: &quot;Trigonometric Function&quot;,
            x_axis: {
                step: 8,
                label_start_from_zero: true
            }
        };

        var d1 = [];
        var d2 = [];
        for (var i = 0; i &lt;= 32; i++) {
            d1.push(Math.round(Math.sin(i * Math.PI / 16) * 1000) / 1000);
            d2.push(Math.round(Math.cos(i * Math.PI / 16) * 1000) / 1000);
        }
        Data.elements[0].values = d1;
        Data.elements[1].values = d2;
        Data.x_axis.labels = [&quot;0&quot;, &quot;π/2&quot;, &quot;π&quot;, &quot;3π/2&quot;, &quot;2π&quot;];

        function GetData() {
            return JSON.stringify(Data);
        }
    &lt;/script&gt;
	&lt;body&gt;
	    &lt;div id=&quot;silverlightControlHost&quot;&gt;
	        &lt;object data=&quot;data:application/x-silverlight,&quot; type=&quot;application/x-silverlight-2&quot;
	            width=&quot;550&quot; height=&quot;250&quot;&gt;
	            &lt;param name=&quot;source&quot; value=&quot;xap/SilverChart.xap&quot; /&gt;
	            &lt;param name=&quot;initParams&quot; value=&quot;onGetData=GetData&quot; /&gt;
	            &lt;a href=&quot;http://go.microsoft.com/fwlink/?LinkID=124807&quot; style=&quot;text-decoration: none;&quot;&gt;
	                &lt;img src=&quot;http://go.microsoft.com/fwlink/?LinkId=108181&quot; alt=&quot;Get Microsoft Silverlight&quot;
	                    style=&quot;border-style: none&quot; /&gt;
	            &lt;/a&gt;
	        &lt;/object&gt;
	        &lt;iframe style='visibility: hidden; height: 0; width: 0; border: 0px'&gt;&lt;/iframe&gt;
	    &lt;/div&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre>
    </div>
    <p>Samples in this site use <a href="http://www.json.org/js.html">Json</a> Javascript package to convert Json object to string.</p>
</body>
</html>""")

application = webapp.WSGIApplication([('/',MainPage)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()